/*!
\copyright  Copyright (c) 2023 Qualcomm Technologies International, Ltd.
            All Rights Reserved.
            Qualcomm Technologies International, Ltd. Confidential and Proprietary.
\file
\brief      Implementation of audio router connect functions for kymera
*/

#include "audio_router_connect.h"

#include "audio_sources.h"
#include "voice_sources.h"
#include "kymera_adaptation.h"

#include <logging.h>

bool AudioRouter_ConnectAudioSource(generic_source_t source)
{
    DEBUG_LOG_FN_ENTRY("%s enum:audio_source_t:%d", __func__, source.u.audio);

    bool success = FALSE;

    connect_parameters_t connect_parameters;

    if(AudioSources_GetConnectParameters(source.u.audio, 
                                            &connect_parameters.source_params))
    {
        connect_parameters.source.type = source_type_audio;
        connect_parameters.source.u.audio = source.u.audio;
        KymeraAdaptation_Connect(&connect_parameters);
        AudioSources_ReleaseConnectParameters(source.u.audio,
                                                &connect_parameters.source_params);
        success = TRUE;
    }
    else
    {
        DEBUG_LOG_ERROR("ERROR - failure getting connection params");
    }

    return success;
}

bool AudioRouter_DisconnectAudioSource(generic_source_t source)
{
    DEBUG_LOG_FN_ENTRY("%s enum:audio_source_t:%d", __func__, source.u.audio);

    bool success = FALSE;
    disconnect_parameters_t disconnect_parameters;

    if(AudioSources_GetDisconnectParameters(source.u.audio, 
                                            &disconnect_parameters.source_params))
    {
        disconnect_parameters.source.type = source_type_audio;
        disconnect_parameters.source.u.audio = source.u.audio;

        KymeraAdaptation_Disconnect(&disconnect_parameters);
        AudioSources_ReleaseDisconnectParameters(source.u.audio,
                                                    &disconnect_parameters.source_params);
        success = TRUE;
    }
    else
    {
        DEBUG_LOG_ERROR("ERROR - failure getting disconnection params");
    }

    return success;
}

bool AudioRouter_ConnectVoiceSource(generic_source_t source)
{
    DEBUG_LOG_FN_ENTRY("%s enum:voice_source_t:%d", __func__, source.u.voice);
    bool success = FALSE;

    connect_parameters_t connect_parameters;

    if(VoiceSources_GetConnectParameters(source.u.voice,&connect_parameters.source_params))
    {
        connect_parameters.source.type = source_type_voice;
        connect_parameters.source.u.voice = source.u.voice;
        KymeraAdaptation_Connect(&connect_parameters);
        VoiceSources_ReleaseConnectParameters(source.u.voice,
                                                &connect_parameters.source_params);
        success = TRUE;
    }
    else
    {
        DEBUG_LOG_ERROR("ERROR - failure getting connection params");
    }

    return success;
}

bool AudioRouter_DisconnectVoiceSource(generic_source_t source)
{
    DEBUG_LOG_FN_ENTRY("%s enum:voice_source_t:%d", __func__, source.u.voice);

    bool success = FALSE;
    disconnect_parameters_t disconnect_parameters;
    if(VoiceSources_GetDisconnectParameters(source.u.voice, 
                                            &disconnect_parameters.source_params))
    {
        disconnect_parameters.source.type = source_type_voice;
        disconnect_parameters.source.u.voice = source.u.voice;

        KymeraAdaptation_Disconnect(&disconnect_parameters);
        VoiceSources_ReleaseDisconnectParameters(source.u.voice, &disconnect_parameters.source_params);

        success = TRUE;
    }
    else
    {
        DEBUG_LOG_ERROR("ERROR - failure getting disconnection params");
    }

    return success;
}
